package teacher.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import leader.bean.MidTable;
import leader.service.MidteaexpService;

import org.apache.struts2.ServletActionContext;

import teacher.bean.Teacher;
import teacher.service.teacher;
import tools.StringDate;

import com.opensymphony.xwork2.ActionSupport;

public class teaInfo extends ActionSupport{
	
	private Teacher teacher;
	private Teacher tea2;
	private List<MidTable> midtable;
	private String[] medatetime;
	private int[] experid;
	String suc;

	public String[] getMedatetime() {
		return medatetime;
	}

	public void setMedatetime(String[] medatetime) {
		this.medatetime = medatetime;
	}

	public int[] getExperid() {
		return experid;
	}

	public void setExperid(int[] experid) {
		this.experid = experid;
	}

	public List<MidTable> getMidtable() {
		return midtable;
	}

	public void setMidtable(List<MidTable> midtable) {
		this.midtable = midtable;
	}

	public String getSuc() {
		return suc;
	}

	public void setSuc(String suc) {
		this.suc = suc;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public String execute()
	{
		HttpServletRequest request=ServletActionContext.getRequest();
		Teacher tea1=(Teacher)request.getSession().getAttribute("teacher");
		tea2=new teacher().SelectTeacher(tea1);
		teacher.setUser(tea2.getUser());
		teacher.setTeaId(tea2.getTeaId());
		teacher.setPower(tea2.getPower());
		teacher.setPassword(tea2.getPassword());
		MidteaexpService midtable = new  MidteaexpService();	
		if(midtable.getCountOfMidTable(teacher)>0) {
			midtable.delMidTableByTeaId(teacher);
		}
		if(null != experid) {
			if(midtable.getCountOfMidTable(teacher)>0) {
				midtable.delMidTableByTeaId(teacher);
			}
			for(int i = 0 ; i < experid.length;i++) {
				midtable.insertMidteaexp(Integer.parseInt(teacher.getTeaId().toString()),experid[i],new StringDate().StringToDate(medatetime[experid[i]-1]));
			}
		}		
		if(new teacher().updateTeacher(teacher, tea2))
		{
			this.setSuc("success");
		return SUCCESS;
		}else{
			return ERROR;
		}
	}

}
